#include <QCoreApplication>
#include <QTextCodec>

#include "Event.h"
#include "SqlInterface.h"
#include "Editor.h"
#include "OptionParser.h"

int main(int argc, char *argv[])
{
    QTextCodec *codec = QTextCodec::codecForName("UTF8");
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForLocale(codec);

    QCoreApplication app(argc, argv);

    SqlInterface::addConnectDB();
    SqlInterface::createDB();
//    SqlInterface::prepareDB();

    qDebug() << "run editor";

    OptionParser parser(app.arguments());
    if (parser.action == OptionParser::INSERT) {
        Event event(EventString(parser.value(OptionParser::OCCUR),
                                parser.value(OptionParser::FORMAT))
                    .normalize());
        event.setName(parser.value(OptionParser::NAME));

        qDebug() << "occur  = " << event.eventString().occur();
        qDebug() << "format = " << event.eventString().format();
        qDebug() << "name   = " << event.name();
        qDebug() << "definition = " << event.definition();

        Editor editor(event);
        if (!editor.insert()) {
            qDebug() << "can't insert!";
        }
    } else if (parser.action == OptionParser::MODIFY) {
        ;
    } else if (parser.action == OptionParser::REMOVE) {
        ;
    }

    return 0;
}
